//#include "stdafx.h"
#include "FlyMoveLgSprite.h"

FlyMoveLgSprite::FlyMoveLgSprite(int nTime,int nPastTime,RECT rect,int nInterVal1,int nInterVal2,
								 const vector<RectInBalloonElemnet_t>& listRect):
m_nTime(nTime),m_nPastTime(nPastTime),m_nInterVal1(nInterVal1),m_nInterVal2(nInterVal2),m_eState(eS1)
{
	m_eClassName=eFlyMoveLgSprite;
	m_StartPos.x=(float)rect.left;
	m_StartPos.y=(float)rect.top;
	m_EndPos.x=(float)rect.right;
	m_EndPos.y=(float)rect.bottom;
	m_vPosition=m_StartPos;
	m_vecHitRect.assign(listRect.begin(),listRect.end());
	if(0!=nTime){
		m_fSpeedx=(m_EndPos.x-m_StartPos.x)/nTime;
		m_fSpeedy=(m_EndPos.y-m_StartPos.y)/nTime;
	}else{
		m_fSpeedx=0;
		m_fSpeedy=0;
	}
}

FlyMoveLgSprite::~FlyMoveLgSprite()
{

}

void FlyMoveLgSprite::Update(DWORD dwCurrentTime)
{
	if(!m_bShow) return;

	DWORD nElpasedTime=0;
	if (-1!=m_nLastTime){
		nElpasedTime=dwCurrentTime-m_nLastTime;
	}

	switch (m_eState){
	case eS1:
		if( m_fAnimationTimer > m_nInterVal1*1000 ) {
			m_fAnimationTimer=0;
			m_eState=eMoving1;
		}
		break;
	case eS2:
		if( m_fAnimationTimer > m_nInterVal2*1000 ) {
			m_fAnimationTimer=0;
			m_eState=eMoving2;
		}
		break;
	case eMoving1:
		if( m_fAnimationTimer > m_nTime*1000 ) {
			m_fAnimationTimer=0;
			m_eState=eS2;
			m_vPosition=m_EndPos;
		}else{
			m_vPosition.x += m_fSpeedx * nElpasedTime/1000;
			m_vPosition.y += m_fSpeedy * nElpasedTime/1000;
		}
		break;
	case eMoving2:
		if( m_fAnimationTimer > m_nTime*1000 ) {
			m_fAnimationTimer=0;
			m_eState=eS1;
			m_vPosition=m_StartPos;
		}else{
			m_vPosition.x -= m_fSpeedx * nElpasedTime/1000;
			m_vPosition.y -= m_fSpeedy * nElpasedTime/1000;
		}
		break;
	}

	DynamicLgSprite::Update(dwCurrentTime);
}